#8/bin/bash
#Variables du script
clean=0
mksql=0
mksqlCache=0
cleanCache=0
action=1
if [ $# -eq 1 ]
then
	case "$1" in
		'clean')
			clean=1
			;;
		'mksql')
			mksql=1
			;;
		'cleanCache'|'cc')
			cleanCache=1
			;;
		'all')
			mksql=1
			clean=1
			;;
		*)
			action=0
			;;
	esac
else
	action=0
fi

#Nettoyage du dossier /var/www/puzzleproject
if [ $clean -eq 1 ]
then
	#suppression puis recreation du dossier /var/www/puzzleproject
	rm -r /var/www/puzzleproject
	#Copy des fichiers
#	cp -rf * /var/www/puzzleproject
	svn export . /var/www/puzzleproject
	chmod 777 /var/www/puzzleproject/ZzG
	chmod 777 /var/www/puzzleproject/ZzConf
	chmod 777 /var/www/puzzleproject/ZzGroup
	chmod -R 777 /var/www/puzzleproject/ZzStore
	chmod -R 777 /var/www/puzzleproject/Log
	chmod -R 777 /var/www/puzzleproject/ZzView
	chmod -R 777 /var/www/puzzleproject/ZzS/gen
	chmod -R 777 /var/www/puzzleproject/ZzT/gen
fi

#Creation de la base de donnée
if [ $mksql -eq 1 ]
then
	wget http://localhost/puzzleproject/dev.php?action=domData -O /dev/null
	echo "data base cleaned"
fi




if [ $cleanCache -eq 1 ]
then
	#suppression des fichiers caches
	wget http://localhost/puzzleproject/dev.php?action=cleanCache -O /dev/null
	echo "ZzG cleaned"
fi

if [ $action -eq 0 ]
then
	echo "Bad parameters"
	echo "clean : re-export puzzleprooject"
	echo "mksql : re-construct the database"
	echo "cleanCache : remove all cache files"
	echo "all : make a new puzzleproject on /var/wwww"
fi
